@@ -124,4 +124,7 @@ ENABLE_INSECURE_AGENTS=false |
||
124 | 124 |
#USE_GRAPHVIZ_DOT=dot |
125 | 125 |
|
126 | 126 |
# Timezone. Use `rake time:zones:local` or `rake time:zones:all` to get your zone name |
127 |
-TIMEZONE="Pacific Time (US & Canada)" |
|
127 |
+TIMEZONE="Pacific Time (US & Canada)" |
|
128 |
+ |
|
129 |
+# Number of failed jobs to keep in the database |
|
130 |
+FAILED_JOBS_TO_KEEP=100 |
@@ -85,12 +85,6 @@ See [private development instructions](https://github.com/cantino/huginn/wiki/Pr |
||
85 | 85 |
|
86 | 86 |
In order to use the WeatherAgent you need an [API key with Wunderground](http://www.wunderground.com/weather/api/). Signup for one and then change the value of `api_key: your-key` in your seeded WeatherAgent. |
87 | 87 |
|
88 |
-#### Enable DelayedJobWeb for handy delayed\_job monitoring and control |
|
89 |
- |
|
90 |
-* Edit `config.ru`, uncomment the DelayedJobWeb section, and change the DelayedJobWeb username and password. |
|
91 |
-* Uncomment `match "/delayed_job" => DelayedJobWeb, :anchor => false` in `config/routes.rb`. |
|
92 |
-* Uncomment `gem "delayed_job_web"` in Gemfile and run `bundle`. |
|
93 |
- |
|
94 | 88 |
#### Disable SSL |
95 | 89 |
|
96 | 90 |
We assume your deployment will run over SSL. This is a very good idea! However, if you wish to turn this off, you'll probably need to edit `config/initializers/devise.rb` and modify the line containing `config.rememberable_options = { :secure => true }`. You will also need to edit `config/environments/production.rb` and modify the value of `config.force_ssl`. |
@@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base |
||
15 | 15 |
end |
16 | 16 |
|
17 | 17 |
def authenticate_admin! |
18 |
- redirect_to root_path unless current_user && current_user.admin |
|
18 |
+ redirect_to(root_path, alert: 'Admin access required to view that page.') unless current_user && current_user.admin |
|
19 | 19 |
end |
20 | 20 |
|
21 | 21 |
def upgrade_warning |
@@ -40,7 +40,7 @@ class JobsController < ApplicationController |
||
40 | 40 |
end |
41 | 41 |
|
42 | 42 |
def destroy_failed |
43 |
- Delayed::Job.where.not(failed_at: nil).destroy_all |
|
43 |
+ Delayed::Job.where.not(failed_at: nil).delete_all |
|
44 | 44 |
|
45 | 45 |
respond_to do |format| |
46 | 46 |
format.html { redirect_to jobs_path, notice: "Failed jobs removed." } |
@@ -38,7 +38,9 @@ |
||
38 | 38 |
<h4 class="modal-title" id="myModalLabel">Error Backtrace</h4> |
39 | 39 |
</div> |
40 | 40 |
<div class="modal-body"> |
41 |
- <%= raw html_escape(job.last_error).split("\n").join('<br/>') %> |
|
41 |
+ <pre> |
|
42 |
+ <%= raw html_escape(job.last_error).split("\n").join('<br/>') %> |
|
43 |
+ </pre> |
|
42 | 44 |
</div> |
43 | 45 |
</div> |
44 | 46 |
</div> |
@@ -36,17 +36,17 @@ |
||
36 | 36 |
</form> |
37 | 37 |
|
38 | 38 |
<li class='job-indicator' role='pending'> |
39 |
- <%= link_to jobs_path do %> |
|
39 |
+ <%= link_to current_user.admin? ? jobs_path : '#' do %> |
|
40 | 40 |
<span class="badge"><span class="glyphicon glyphicon-refresh icon-white"></span> <span class='number'>0</span></span> |
41 | 41 |
<% end %> |
42 | 42 |
</li> |
43 | 43 |
<li class='job-indicator' role='awaiting_retry'> |
44 |
- <%= link_to jobs_path do %> |
|
44 |
+ <%= link_to current_user.admin? ? jobs_path : '#' do %> |
|
45 | 45 |
<span class="badge"><span class="glyphicon glyphicon-question-sign icon-yellow"></span> <span class='number'>0</span></span> |
46 | 46 |
<% end %> |
47 | 47 |
</li> |
48 | 48 |
<li class='job-indicator' role='recent_failures'> |
49 |
- <%= link_to jobs_path do %> |
|
49 |
+ <%= link_to current_user.admin? ? jobs_path : '#' do %> |
|
50 | 50 |
<span class="badge"><span class="glyphicon glyphicon-exclamation-sign icon-white"></span> <span class='number'>0</span></span> |
51 | 51 |
<% end %> |
52 | 52 |
</li> |
@@ -2,12 +2,4 @@ |
||
2 | 2 |
|
3 | 3 |
require ::File.expand_path('../config/environment', __FILE__) |
4 | 4 |
|
5 |
-# To enable DelayedJobWeb, see the 'Enable DelayedJobWeb' section of the README. |
|
6 |
- |
|
7 |
-# if Rails.env.production? |
|
8 |
-# DelayedJobWeb.use Rack::Auth::Basic do |username, password| |
|
9 |
-# username == 'admin' && password == 'password' |
|
10 |
-# end |
|
11 |
-# end |
|
12 |
- |
|
13 | 5 |
run Huginn::Application |
@@ -32,6 +32,11 @@ class HuginnScheduler |
||
32 | 32 |
end |
33 | 33 |
end |
34 | 34 |
|
35 |
+ def cleanup_failed_jobs! |
|
36 |
+ first_to_delete = Delayed::Job.where.not(failed_at: nil).order("failed_at DESC").offset(ENV['FAILED_JOBS_TO_KEEP'].try(:to_i) || 100).limit(ENV['FAILED_JOBS_TO_KEEP'].try(:to_i) || 100).pluck(:failed_at).first |
|
37 |
+ Delayed::Job.where(["failed_at <= ?", first_to_delete]).delete_all if first_to_delete.present? |
|
38 |
+ end |
|
39 |
+ |
|
35 | 40 |
def with_mutex |
36 | 41 |
ActiveRecord::Base.connection_pool.with_connection do |
37 | 42 |
mutex.synchronize do |
@@ -57,6 +62,13 @@ class HuginnScheduler |
||
57 | 62 |
cleanup_expired_events! |
58 | 63 |
end |
59 | 64 |
|
65 |
+ # Schedule failed job cleanup. |
|
66 |
+ |
|
67 |
+ @rufus_scheduler.every '1h' do |
|
68 |
+ cleanup_failed_jobs! |
|
69 |
+ end |
|
70 |
+ |
|
71 |
+ |
|
60 | 72 |
# Schedule repeating events. |
61 | 73 |
|
62 | 74 |
%w[1m 2m 5m 10m 30m 1h 2h 5h 12h 1d 2d 7d].each do |schedule| |
@@ -25,7 +25,7 @@ describe JobsHelper do |
||
25 | 25 |
relative_distance_of_time_in_words(Time.now-5.minutes).should == '5m ago' |
26 | 26 |
end |
27 | 27 |
|
28 |
- it "in the furute" do |
|
28 |
+ it "in the future" do |
|
29 | 29 |
relative_distance_of_time_in_words(Time.now+5.minutes).should == 'in 5m' |
30 | 30 |
end |
31 | 31 |
end |